#ifndef SOURCETREE_H
#define SOURCETREE_H

#include <QTreeWidget>

class DokerModel;

class SourceItem : public QTreeWidgetItem
{
public:
    enum ItemType
    {
        GroupType = QTreeWidgetItem::UserType + 1,
        FolderType = QTreeWidgetItem::UserType + 2,
        FileType = QTreeWidgetItem::UserType + 3
    };
    SourceItem(QTreeWidget *view, const QString &fileName, int type = Type)
        : QTreeWidgetItem(view, QStringList() << fileName, type)
    { m_fileName = fileName; }
    SourceItem(QTreeWidgetItem *parent, const QString &fileName, int type = Type)
        : QTreeWidgetItem(parent, QStringList() << fileName, type)
    { m_fileName = fileName; }

    bool isGroup() { return type() == GroupType; }
    bool isFolder() { return type() == FolderType; }
    bool isFile() { return type() == FileType; }
    const QString &fileName() {return m_fileName; }
private:
    QString m_fileName;
};

class SourceTree : public QTreeWidget
{
    Q_OBJECT
public:
    explicit SourceTree(DokerModel *model, QWidget *parent = 0);
    
signals:
    
public slots:

protected:
    void mouseDoubleClickEvent(QMouseEvent *event);

private slots:
    void addItem(const QString &groupName, const QString &itemName);
    void update(const QString &fileName, bool modified);

private:
    SourceItem *findGroupItem(const QString &fileName);
    SourceItem *findFileItem(const QString &fileName);

private:
    DokerModel  *m_model;

};

#endif // SOURCETREE_H
